#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1500005, mod = 1000000007;
vector<int> G[MAXN]; int dep[MAXN], fa[MAXN]; bool vis[MAXN]; int n, k;
void dfs(int u, int f) {
	dep[u] = u == f ? 0 : dep[f] + 1; fa[u] = f; for (int v : G[u]) if (v != f) dfs(v, u);
}
int mxd[MAXN], siz[MAXN];
void dfs2(int u, int f) {
	siz[u] = 1; for (int v : G[u]) if (v != f && vis[v] == 0) dfs2(v, u), mxd[u] = max(mxd[u], mxd[v] + 1), siz[u] += siz[v];
}
struct VAL {bool flg; int ans; VAL(int x = 0) {flg = x; ans = x;} VAL(bool w, int x) {flg = w; ans = x;}};
VAL operator + (const VAL &x, const VAL &y) {return {x.flg || y.flg, (x.ans + y.ans) % mod};}
VAL operator * (const VAL &x, const VAL &y) {return {x.flg && y.flg, 1ll * x.ans * y.ans % mod};}
pair<VAL, VAL> dfs25(int u, int f, int d) {
	VAL x = 1, y = 1;
	for (int v : G[u]) if (v != f && vis[v] == 0) {
		auto w = dfs25(v, u, d + 1); x = x * w.first; y = y * w.second;
	}
	if (u == f) return {x, 0};
	if (d > k) x = 0; else x = x + y;
	return {x, y};
}
VAL dfs3(int u, int f, int d) {
	if (d == k) d = 0; VAL ans = 1;
	for (int v : G[u]) if (v != f && vis[v] == 0) ans = ans * dfs3(v, u, d + 1);
	static int mx, mx2; mx = -1; mx2 = -1;
	for (int v : G[u]) if (v != f && vis[v] == 0) {
		int w = mxd[v] + 1; if (w > mx) mx2 = mx, mx = w; else if (w > mx2) mx2 = w;
	}
	if (mx2 == -1) return ans;
	else if (mx + mx2 + 1 < k) return ans;
	else if (d * 2 == k || d == 0) return ans;
	else return 0;
}
int read() {
	char ch; while ((ch = getchar()) <= ' '); int x = ch - '0';
	while ((ch = getchar()) > ' ') x = 10 * x + ch - '0'; return x;
}
int main() {
	freopen("life.in", "r", stdin); freopen("life.out", "w", stdout);
	n = read(); k = read();
	for (int i = 1; i < n; i++) {
		int u = read(), v = read(); G[u].push_back(v); G[v].push_back(u);
	}
	dfs(1, 1); int p = 1; for (int i = 2; i <= n; i++) p = dep[i] > dep[p] ? i : p;
	dfs(p, p); int q = 1; for (int i = 2; i <= n; i++) q = dep[i] > dep[q] ? i : q;
	vector<int> dia; dia.push_back(q); for (int _ = q; _ != p; _ = fa[_]) dia.push_back(fa[_]);
	if ((int)dia.size() < k) {
		int ans = 1; for (int i = 1; i <= n; i++) ans = 2 * ans % mod;
		printf("YES\n%d\n", ans);
	}
	else {
		static VAL pw2[MAXN];
		pw2[0] = 1; for (int i = 1; i <= n; i++) pw2[i] = 2 * pw2[i - 1];
		
		int m = dia.size();
		for (int u : dia) vis[u] = 1;
		for (int u : dia) dfs2(u, u);

		VAL glb = 1; static int fil[MAXN], fid[MAXN]; vector<int> dfslist[MAXN];

		for (int i = 0; i < m; i++) {
			int d = mxd[dia[i]];
			if (d < k / 2) {
				bool lf = d + i + 1 >= k;
				bool rt = d + m - i >= k;
				// printf("?? %d - %d %d(d %d)\n", i, lf, rt, d);
				if (lf == 0 && rt == 0) {
					glb = glb * pw2[siz[dia[i]] - 1];
				}
				else if (lf == 0 || rt == 0) {
					continue;
					// printf("??? %d\n", i);
					// glb = glb * dfs25(dia[i], dia[i], max(i + 1, m - i)).first;
					// printf("?? get %d\n", dfs25(dia[i], dia[i], max(i + 1, m - i)).first.ans);
				}
				else {
					int p = i % k;
					fid[p]--;
					fil[(p - d + k) % k]++; fil[(p + d + 1) % k]--;
					if (p - d < 0 || p + d + 1 >= k) fil[0]++;
				}
			}
			else {
				fil[0]++; fid[i % k]--; dfslist[i % k].push_back(i);
				if (k % 2 == 0) fid[(i + k / 2) % k]--, dfslist[(i + k / 2) % k].push_back(i);
			}
		}
		for (int i = 1; i < k; i++) fil[i] += fil[i - 1];
		for (int i = 0; i < k; i++) fil[i] += fid[i];
		VAL ret;
		for (int i = 0; i < k; i++) {
			if (fil[i]) continue;
			printf("%d\n", i);
			VAL ans = glb;
			for (int u : dfslist[i]) {
				if (u % k == i) ans = ans * dfs3(u, u, 0);
				else ans = ans * dfs3(u, u, k / 2);
			}
			ret = ret + ans;
		}
		printf("%s\n%d\n", ret.flg ? "YES" : "NO", ret.ans);
	}
}
/*
7 2
1 2
2 3
3 4
1 5
1 6
1 7
*/